package com.exam.api.config.validation;

import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Locale;

/**
 * @Author bcheng
 * @Create 2024/1/13 12:11
 * @Description Validated配置类
 */
@Configuration
public class ValidatedConfig {
    @Bean
    public Validator validator() {
        ValidatorFactory factory = Validation.byProvider(HibernateValidator.class)
                .configure().defaultLocale(Locale.CHINA)
                .failFast(true)
                .buildValidatorFactory();
        return factory.getValidator();
    }
}
